<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$appConfigs.title}</title>
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/{$page_theme | default: 'default'}/easyui.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/editor/themes/default/default.css" />
    
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.patch.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/editor/kindeditor-min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/editor/lang/zh_CN.js"></script>
</head> 
<body onpageshow="resetPagination()">
    <table id="dg" title="所有信息" class="easyui-datagrid" style="width:99%;height:95%"
            url="/cms/content/findAllByCategoryCode.xdo?code={$Request.code}"
            toolbar="#toolbar" pagination="true" pageSize="15" pageList="[15,30]"
            rownumbers="true" fitColumns="true" singleSelect="false">
        <thead>
            <tr>
                <th field="category_name" width="40">栏目</th>
                <th field="title" width="50">标题</th>
                <th field="tag" width="50" data-options="formatter:{literal}function(v){return v=='TOP'?'是':(v=='TOP1'?'块1':(v=='TOP2'?'块2':'-'))}{/literal}">首页</th>
                <th field="tag2" width="50" data-options="formatter:{literal}function(v){return v=='TOP'?'是':'-'}{/literal}">置顶</th>
                <th field="sort_id" width="30" align="right">排序</th>
                <th field="status" width="30" data-options="formatter:{literal}function(v){return v=='1'?'已发布':'<font color=red>未发布</font>'}{/literal}">状态</th>
                <th field="publish_date" width="30">发布时间</th>
                <th field="create_date" width="30">创建时间</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="createOne()">新建</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="updateOne()">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-man" plain="true" onclick="publishOne()">发布</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-man" plain="true" onclick="unpublishOne()">取消发布</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeOne()">删除</a>
    </div>
    
    <div id="dlg" class="easyui-dialog" style="width:800px; height:470px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">信息</div>
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>栏目:</label>
                {if $Request.code == "HUMANISTIC" or  $Request.code == "WORKGUIDE"}
				<select name="category_id" id="category_id" class="easyui-combotree" style="width:200px;" 
						data-options="url:'/cms/category/findChildrenTreeByCode.xdo?code={$Request.code}',required:true">
				</select>
				{elseif $Request.code == "POLICIES" }
				<select name="category_id" id="category_id" class="easyui-combotree" style="width:200px;" 
						data-options="url:'/cms/category/findChildrenTreeByCode.xdo?code={$Request.code}',required:true">
				</select>
				{else}
                {$categoryObject.name}
				{/if}
            </div>
            <div class="fitem">
                <label>标题:</label>
                <input id="title" name="title" class="easyui-textbox" required="true" style="width:500px" maxlength='20'>
            </div>
            <div class="fitem">
                <label>标签:</label>
                {if $Request.code == 'LAW' or $Request.code == 'TECH' or $Request.code == 'ENVIRONMENT'}
                <input name="tag" type="radio" style="width:30px" value="">普通&nbsp;&nbsp;
                <input name="tag" type="radio" style="width:30px" value="TOP1">首页块1&nbsp;&nbsp;
                <input name="tag" type="radio" style="width:30px" value="TOP2">首页块2 &nbsp;
                {else}
                <input id="tag1" name="tag" type="checkbox" style="width:30px" value="TOP" checked="true">首页 &nbsp;
                {/if}
                <input id="tag2" name="tag2" type="checkbox" style="width:30px" value="TOP">要闻
            </div>
            <div class="fitem">
                <label>来源:</label>
                <input id="source" name="source" class="easyui-textbox" style="width:500px" value="">
            </div>
            <div class="fitem">
                <label>链接URL:</label>
                <input id="link" name="link" class="easyui-textbox" data-options="prompt:'输入链接URL则新闻直接转跳到对应的外网链接，不需要请留空'" style="width:500px">
            </div>
            <div class="fitem">
                <label>排序:</label>
                <input id="sort_id" name="sort_id" class="easyui-numberbox" value="0">
            </div>
            <div class="fitem">
                <label>内容:</label>
		        <textarea id="content" name="content" cols="150" rows="8" class="txtContent"
		            style="width: 90%; height: 170px; visibility: hidden;"></textarea>
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOne()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
    var category_id = '{$categoryObject.category_id}';
    var category_code='{$categoryObject.code}';
    {literal}
        var url;
        function createOne(){
            $('#dlg').dialog('open').dialog('setTitle','新增');
            $('#fm').form('clear');
            var tag1 = document.getElementById("tag1");
            if(tag1){
            	tag1.checked = "true";
            }
			editor.html("");
			if (category_code == 'HUMANISTIC' || category_code == 'POLICIES' || category_code == 'WORKGUIDE')
            	url = '/cms/content/create.xdo';
            else
            	url = '/cms/content/create.xdo?category_id=' + category_id;
        }
        function updateOne(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','修改');
                $('#fm').form('load',row);
				editor.html(row.content);
				if (category_code == 'HUMANISTIC' || category_code == 'POLICIES' || category_code == 'WORKGUIDE')
               		url = '/cms/content/update.xdo?content_id='+row.content_id;
	            else
	            	url = '/cms/content/update.xdo?category_id=' + row.category_id+'&content_id='+row.content_id;
            }
        }
        function saveOne(){
            if(document.getElementById("title").value.length > 200){
        		$.messager.show({
                            title: 'Error',
                            msg: '标题超过200个字符'
                        });
        		return;
        	}
        	if(document.getElementById("source").value.length > 50){
        		$.messager.show({
                            title: 'Error',
                            msg: '来源超过50个字符'
                        });
        		return;
        	}        	
        	if(document.getElementById("sort_id").value.length > 10){
        		$.messager.show({
                            title: 'Error',
                            msg: '排序超过10位'
                        });
        		return;
        	}
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
						$('#parent_id').combotree('reload');
                    }
                }
            });
        }
        function removeOne(){
            var selections = $('#dg').datagrid('getSelections');
            if (selections.length > 0 ){
            	var rows = new Array();
            	for(var i=0; i< selections.length; i++){
            		rows.push(selections[i].content_id);
            	}
                $.messager.confirm('Confirm','删除后数据不能恢复，确认删除么?',function(r){
                    if (r){
                        $.post('/cms/content/remove.xdo',{content_id:rows},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function publishOne(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','发布后，其他系统将可以查到此数据，确认发布么?',function(r){
                    if (r){
                        $.post('/cms/content/publish.xdo',{content_id:row.content_id},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function unpublishOne(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确认取消发布么?',function(r){
                    if (r){
                        $.post('/cms/content/unpublish.xdo',{content_id:row.content_id},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
		function resetPagination(){
			var p = $('#dg').datagrid('getPager');
			$(p).pagination({             
				pageSize: 15,           
		 		pageList: [15,30],
				beforePageText: '第',      
				afterPageText: '页    共 {pages} 页',             
				displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'                  
			}); 
		}
    </script>
    <script type="text/javascript">
        //编辑器
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager: false,
                resizeType: 1,
                allowPreviewEmoticons: false,
                items: [
                    'preview', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', 'quickformat', '|', 'emoticons', 'image', 'link','|', 'fullscreen','source'],
                afterChange: function () {
                    this.sync();
                }
            });
        });
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
    {/literal}
</body>
</html>